package cn.com.header.zbpk.web.controller;

import cn.com.header.core.support.web.ResultCode;
import cn.com.header.core.support.web.springmvc.FileDownloadBaseController;
import cn.com.header.zbpk.exception.ServiceException;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.File;
import java.io.IOException;

/**
 * 文件模板下载前端控制器
 *
 * @author luohaidian
 * @date 2017-11-20
 * @time 14:05
 */
@Controller
@RequestMapping(value = "/manage/file/template")
public class FileDownloadController extends FileDownloadBaseController {

    private final String filePath = "/exceltemp/accountTemplet.zip";

    /**
     * 账号模板下载
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/account/download")
    public ResponseEntity<byte[]> download() throws IOException {
        String path = this.getClass().getResource(filePath).getFile();
        File file = new File(path);
        if (!file.exists()){
            throw new ServiceException(ResultCode.NO_EXISTS, "账号导入模板文件不存在！！！");
        }
        return writeToResponseForDownload(file);
    }

}
